package com.dunqi.gpm.shunqing.home.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.dunqi.gpm.shunqing.R;
import com.dunqi.gpm.shunqing.common.base.RecyclerAdapter;
import com.dunqi.gpm.shunqing.common.util.CommonUtil;
import com.dunqi.gpm.shunqing.common.util.SpannableStringUtils;
import com.dunqi.gpm.shunqing.home.bean.EarlyInfo;
import com.dunqi.gpm.shunqing.home.constance.Constance;
import com.dunqi.gpm.shunqing.home.fragment.HomeFragment;

import java.util.List;

/**
 * Created by Administrator on 2017/11/26.
 */
public class EarlyInfoAdapter extends RecyclerAdapter<EarlyInfo> {

    private final String[] status;
    private final String[] stageStatuss;
    private int[] resIds;

    public EarlyInfoAdapter(@Nullable List<EarlyInfo> data) {
        super(R.layout.item_early_info, data);
        status = Constance.STATUS;

        //    0 创建
//1 提交审批申请(实际启动)
//2 完成审批(实际完成)
        resIds = new int[]{R.mipmap.yub, R.mipmap.yub, R.mipmap.yuy, R.mipmap.yur};

        stageStatuss = new String[]{"待申请", "待完成", "已完成"};
    }

    @Override
    protected void convert(BaseViewHolder helper, EarlyInfo item) {

        TextView resp_org_name_tv = helper.getView(R.id.resp_org_name_tv);
        resp_org_name_tv.setText("负责单位:" + item.getRespOrgName());

        int light = item.getLight();
        ImageView light_iv = helper.getView(R.id.light_iv);
        light_iv.setVisibility(View.GONE);
        if (light == 0) {
            light_iv.setVisibility(View.GONE);
        } else {
            light_iv.setVisibility(View.VISIBLE);
            light_iv.setImageResource(resIds[light]);
        }

        TextView state_name_tv = helper.getView(R.id.state_name_tv);
        state_name_tv.setText("阶段名称:" + item.getStageName());

        int stageStatus = item.getStageStatus();

        TextView audit_status_tv = helper.getView(R.id.audit_status_tv);

        int color;
        if (stageStatus == 0) {
            color = CommonUtil.getColor(R.color.material_deep_orange_400);
        } else {
            color = CommonUtil.getColor(R.color.action_text_color_enabled);
        }

        audit_status_tv.setText(SpannableStringUtils.getBuilder("状态:")
                .append(stageStatuss[stageStatus])
                .setForegroundColor(color)
                .create());


        TextView commitTv = helper.getView(R.id.commit_tv);
        int type = HomeFragment.homeMenuId;


        String text = "";
        commitTv.setVisibility(View.VISIBLE);
        commitTv.setText(text);

        /*
        NormalView nickNameview = helper.getView(R.id.nick_name_view);
        nickNameview.setText(item.getStageName());

        NormalView companyView = helper.getView(R.id.company_view);
        companyView.setText(item.getRespOrgName());

        NormalView nameview = helper.getView(R.id.name_view);
        nameview.setText(item.getRespOrgLeaderName());

        NormalView phoneView = helper.getView(R.id.phone_view);
        phoneView.setText(item.getRespOrgLeaderPhone());

        NormalView levelView = helper.getView(R.id.level_view);
        levelView.setText(item.getAuditLevelText());

        NormalView cycleView = helper.getView(R.id.cycle_view);
        cycleView.setText(String.valueOf(item.getIntervalDays()));

        NormalView isCompletedView = helper.getView(R.id.is_completed_view);
        isCompletedView.setText(item.getStageStatus() == 2 ? "是" : "否");

        NormalView planStartTimeView = helper.getView(R.id.plan_start_time_view);
        planStartTimeView.setText(item.getPlanStartTime());
        NormalView planEndTimeView = helper.getView(R.id.plan_end_time_view);
        planEndTimeView.setText(item.getPlanCompleteTime());

        NormalView actualStartTimeView = helper.getView(R.id.actual_start_time_view);
        actualStartTimeView.setText(item.getActualStartTime());

        NormalView actualEndTimeView = helper.getView(R.id.actual_end_time_view);
        actualEndTimeView.setText(item.getActualCompleteTime());

        NormalView questionView = helper.getView(R.id.question_view);
        questionView.setText(item.getExistedProblem());

        NormalView remarkView = helper.getView(R.id.remarks_view);
        remarkView.setText(item.getRemark());

        int stageStatus = item.getStageStatus();

        NormalView audit_status_view = helper.getView(R.id.audit_status_view);
        audit_status_view.setText(stageStatuss[stageStatus]);
        if (stageStatus == 0) {
            audit_status_view.setTextColor(R.color.material_deep_orange_400);
        } else {
            audit_status_view.setTextColor(R.color.action_text_color_enabled);
        }

        int levelType = UserUtil.getLevelType();
        TextView commitTv = helper.getView(R.id.commit_tv);
        int homeMenuId = HomeFragment.homeMenuId;

        String text;
        commitTv.setVisibility(View.VISIBLE);

        if (stageStatus == 0 && homeMenuId == 10) {
            text = "提交审批";
        } else {
            text = "";
        }
        commitTv.setText(text);
        */

    }

}
